package org.jeecg.modules.xdbuse.service.impl;

import org.jeecg.modules.xdbuse.entity.FxjBuse01;
import org.jeecg.modules.xdbuse.entity.FxjBuse0110;
import org.jeecg.modules.xdbuse.entity.FxjBuse0120;
import org.jeecg.modules.xdbuse.entity.FxjBuse0130;
import org.jeecg.modules.xdbuse.entity.FxjBuse0140;
import org.jeecg.modules.xdbuse.entity.FxjBuse0150;
import org.jeecg.modules.xdbuse.entity.FxjBuse0160;
import org.jeecg.modules.xdbuse.mapper.FxjBuse0110Mapper;
import org.jeecg.modules.xdbuse.mapper.FxjBuse0120Mapper;
import org.jeecg.modules.xdbuse.mapper.FxjBuse0130Mapper;
import org.jeecg.modules.xdbuse.mapper.FxjBuse0140Mapper;
import org.jeecg.modules.xdbuse.mapper.FxjBuse0150Mapper;
import org.jeecg.modules.xdbuse.mapper.FxjBuse0160Mapper;
import org.jeecg.modules.xdbuse.mapper.FxjBuse01Mapper;
import org.jeecg.modules.xdbuse.service.IFxjBuse01Service;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 订单管理
 * @Author: zhaodui
 * @Date:   2020-02-20
 * @Version: V1.0
 */
@Service
public class FxjBuse01ServiceImpl extends ServiceImpl<FxjBuse01Mapper, FxjBuse01> implements IFxjBuse01Service {

	@Autowired
	private FxjBuse01Mapper fxjBuse01Mapper;
	@Autowired
	private FxjBuse0110Mapper fxjBuse0110Mapper;
	@Autowired
	private FxjBuse0120Mapper fxjBuse0120Mapper;
	@Autowired
	private FxjBuse0130Mapper fxjBuse0130Mapper;
	@Autowired
	private FxjBuse0140Mapper fxjBuse0140Mapper;
	@Autowired
	private FxjBuse0150Mapper fxjBuse0150Mapper;
	@Autowired
	private FxjBuse0160Mapper fxjBuse0160Mapper;
	
	@Override
	@Transactional
	public void saveMain(FxjBuse01 fxjBuse01, List<FxjBuse0110> fxjBuse0110List,List<FxjBuse0120> fxjBuse0120List,List<FxjBuse0130> fxjBuse0130List,List<FxjBuse0140> fxjBuse0140List,List<FxjBuse0150> fxjBuse0150List,List<FxjBuse0160> fxjBuse0160List) {
		fxjBuse01Mapper.insert(fxjBuse01);
		if(fxjBuse0110List!=null && fxjBuse0110List.size()>0) {
			for(FxjBuse0110 entity:fxjBuse0110List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0110Mapper.insert(entity);
			}
		}
		if(fxjBuse0120List!=null && fxjBuse0120List.size()>0) {
			for(FxjBuse0120 entity:fxjBuse0120List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0120Mapper.insert(entity);
			}
		}
		if(fxjBuse0130List!=null && fxjBuse0130List.size()>0) {
			for(FxjBuse0130 entity:fxjBuse0130List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0130Mapper.insert(entity);
			}
		}
		if(fxjBuse0140List!=null && fxjBuse0140List.size()>0) {
			for(FxjBuse0140 entity:fxjBuse0140List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0140Mapper.insert(entity);
			}
		}
		if(fxjBuse0150List!=null && fxjBuse0150List.size()>0) {
			for(FxjBuse0150 entity:fxjBuse0150List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0150Mapper.insert(entity);
			}
		}
		if(fxjBuse0160List!=null && fxjBuse0160List.size()>0) {
			for(FxjBuse0160 entity:fxjBuse0160List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0160Mapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional
	public void updateMain(FxjBuse01 fxjBuse01,List<FxjBuse0110> fxjBuse0110List,List<FxjBuse0120> fxjBuse0120List,List<FxjBuse0130> fxjBuse0130List,List<FxjBuse0140> fxjBuse0140List,List<FxjBuse0150> fxjBuse0150List,List<FxjBuse0160> fxjBuse0160List) {
		fxjBuse01Mapper.updateById(fxjBuse01);
		
		//1.先删除子表数据
		fxjBuse0110Mapper.deleteByMainId(fxjBuse01.getId());
		fxjBuse0120Mapper.deleteByMainId(fxjBuse01.getId());
		fxjBuse0130Mapper.deleteByMainId(fxjBuse01.getId());
		fxjBuse0140Mapper.deleteByMainId(fxjBuse01.getId());
		fxjBuse0150Mapper.deleteByMainId(fxjBuse01.getId());
		fxjBuse0160Mapper.deleteByMainId(fxjBuse01.getId());
		
		//2.子表数据重新插入
		if(fxjBuse0110List!=null && fxjBuse0110List.size()>0) {
			for(FxjBuse0110 entity:fxjBuse0110List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0110Mapper.insert(entity);
			}
		}
		if(fxjBuse0120List!=null && fxjBuse0120List.size()>0) {
			for(FxjBuse0120 entity:fxjBuse0120List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0120Mapper.insert(entity);
			}
		}
		if(fxjBuse0130List!=null && fxjBuse0130List.size()>0) {
			for(FxjBuse0130 entity:fxjBuse0130List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0130Mapper.insert(entity);
			}
		}
		if(fxjBuse0140List!=null && fxjBuse0140List.size()>0) {
			for(FxjBuse0140 entity:fxjBuse0140List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0140Mapper.insert(entity);
			}
		}
		if(fxjBuse0150List!=null && fxjBuse0150List.size()>0) {
			for(FxjBuse0150 entity:fxjBuse0150List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0150Mapper.insert(entity);
			}
		}
		if(fxjBuse0160List!=null && fxjBuse0160List.size()>0) {
			for(FxjBuse0160 entity:fxjBuse0160List) {
				//外键设置
				entity.setQuery01(fxjBuse01.getId());
				fxjBuse0160Mapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional
	public void delMain(String id) {
		fxjBuse0110Mapper.deleteByMainId(id);
		fxjBuse0120Mapper.deleteByMainId(id);
		fxjBuse0130Mapper.deleteByMainId(id);
		fxjBuse0140Mapper.deleteByMainId(id);
		fxjBuse0150Mapper.deleteByMainId(id);
		fxjBuse0160Mapper.deleteByMainId(id);
		fxjBuse01Mapper.deleteById(id);
	}

	@Override
	@Transactional
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			fxjBuse0110Mapper.deleteByMainId(id.toString());
			fxjBuse0120Mapper.deleteByMainId(id.toString());
			fxjBuse0130Mapper.deleteByMainId(id.toString());
			fxjBuse0140Mapper.deleteByMainId(id.toString());
			fxjBuse0150Mapper.deleteByMainId(id.toString());
			fxjBuse0160Mapper.deleteByMainId(id.toString());
			fxjBuse01Mapper.deleteById(id);
		}
	}
	
}
